﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;

namespace mForum.Core.Infrastructure.Configuration
{
    using mForum.Core.Common;

    public class ConfigurationWrapper : IConfigurationWrapper
    {
        private string _providerName;
        private string _connectionString;

        public NameValueCollection AppSettings
        {
            get
            {
                return ConfigurationManager.AppSettings;
            }
        }

        public IConfigurationWrapper SetConnectionString(string name)
        {
            Check.Argument.IsNotEmpty(name, "ConnectionStringName");

            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings[name];
            _providerName = connectionStringSettings.ProviderName;
            _connectionString = connectionStringSettings.ConnectionString;

            return this;
        }

        public string ProviderName
        {
            get { return _providerName; }
        }

        public string ConnectionString
        {
            get { return _connectionString; }
        }

        public T GetSection<T>(string sectionName)
        {
            Check.Argument.IsNotNull(sectionName, "sectionName");

            return (T)ConfigurationManager.GetSection(sectionName);
        }
    }
}
